package com.xjc.agent.core.intercept;

import com.xjc.agent.core.collector.DataCollector;
import com.xjc.agent.core.collector.DataCollectorImpl;
import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

/**
 * @author: 谢君臣
 * @Date: 2023/1/1-17:05
 * @version: 1.0
 * @function:
 */

public class MonitorMethod {

    private static DataCollector dataCollector = new DataCollectorImpl();

    @RuntimeType
    public static Object intercept(@Origin Class clazz,
                            @Origin Method method,
                            @SuperCall Callable<?>callable,
                            @AllArguments Object[] args){
        try {
            System.out.println("+++++++++++ MonitorMethod +++++++++++");
            dataCollector.collector(clazz.getName() + "send mq!");
            return callable.call();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
